package com.mjk.datasource;


import com.mjk.api.dto.ApiDto;
import com.mjk.common.base.error.BeeError;
import com.mjk.common.base.response.BeeResponse;
import com.mjk.common.base.work.BaseWork;
import com.mjk.common.base.work.annotation.BeeApi;
import com.mjk.common.base.work.annotation.BeeWork;
import com.mjk.common.core.jdbc.service.plus.idbservice.BeeDBService;
import com.mjk.common.core.jdbc.service.plus.wrap.BeeComplexQueryWrapper;
import com.mjk.datasource.mapper.ComplexSqlMapper;
import com.mjk.datasource.model.ApiDetailModel;
import com.mjk.datasource.model.MiProperties;
import com.mjk.manager.api.model.ApiModel;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;

@BeeWork(work = "complexsql")
public class ComplexSqlExample extends BaseWork {

    @Autowired
    private ComplexSqlMapper mapper;

    @Autowired
    private BeeDBService beeDBService;

    public BeeResponse getTableInfo(ApiDto dto){
        return BeeError.BEE_SUC.tranceError(mapper.getMiProperties(dto));
    }

    @BeeApi
    public BeeResponse getComplexInfo(ApiDto dto){
        BeeComplexQueryWrapper wrapper = new BeeComplexQueryWrapper(new ApiModel(), "api");
        wrapper.select("""
                a.id,a.nodeName,a.nodeType,a.params,a.parentId,
                b.BAK1,b.BAK2,b.BAK3,b.DEL_FLAG
                """);
        wrapper.innerJoin(ApiDetailModel.class, "a").on(ApiModel::getId, ApiDetailModel::getApiId);
        wrapper.leftJoin(MiProperties.class,"b").on(ApiModel::getId,MiProperties::getId);
        wrapper.eq(ApiModel::getId, 1);
        List<ApiModel> properties = beeDBService.findManyByComplexWrapper(wrapper);
        return BeeError.BEE_SUC.tranceError(properties);
    }
}
